package cn.base.demo3;

public class Code14 {
    public static void main(String[] args) {

        //冒泡排序
        int[] arr = {1, 11, 2, 30, 60, 70, 15};
        for (int i = 0; i < arr.length; i++) {
            int maxIndex = i;//用来记录最大值的索引
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[maxIndex] < arr[j]) {
                    maxIndex = j;//获取最大值的索引
                }
            }
            if (maxIndex != i) {
                int temp = arr[maxIndex];
                arr[maxIndex] = arr[i];
                arr[i] = temp;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
    }
}
